package com.meilai.project.controller.web.business.installOrder;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.meilai.project.dto.base.ApiResult;
import com.meilai.project.dto.business.installOrder.WorkerRepairPointDTO;
import com.meilai.project.service.business.installOrder.WorkOrderService;
import com.meilai.project.service.business.installOrder.WorkerSubmitService;
import com.meilai.project.vo.business.installOrder.WorkerRepairPointVO;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author xchen
 * @since 2022-04-04
 */
@RestController
@RequestMapping("api/web/worker_repair")
public class WorkerRepairController {

	@Autowired
	private WorkerSubmitService workerSubmitService;

	@Autowired
	private WorkOrderService workOrderService;

	@GetMapping("/list")
	@ApiOperation("待维修点位列表")
	public ApiResult<Page<WorkerRepairPointVO>> list(@ApiParam("form") WorkerRepairPointDTO req){
		Page<WorkerRepairPointVO> workerRepairPointVOPage = workerSubmitService.selectListNeedRepairPoint(req);
		return ApiResult.ok(workerRepairPointVOPage);
	}

	@GetMapping("/total")
	@ApiOperation("待维修点位总数")
	public ApiResult<Integer> total(){
		Integer total = workerSubmitService.listTotal();
		return ApiResult.ok(total);
	}

	@PostMapping("submit")
	@ApiOperation("提交维修单")
	public ApiResult<Boolean> submit(@ApiParam("json") @RequestBody WorkerRepairPointDTO req) {
		workOrderService.submitRepairOrder(req);
		return ApiResult.ok();
	}
}
